<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>修改信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style type="text/css">
        body {
            background-color: #ffffff;
        }
        /* 设置下拉框宽度 */
        /* input.layui-input.layui-unselect {width:400px} */
    </style>

</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">计划编号</label>
        <div class="layui-input-block">
            <input type="hidden" name="matId" id="matid" value="" class="layui-input" />
            <input style="width: 400px;" type="text" name="planid" lay-verify="required" lay-reqtext="计划编号不能为空" placeholder="请输入计划编号" value="" class="layui-input">
            <tip><!-- 填写计划编号。 --></tip>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">申领人姓名</label>
        <div class="layui-input-block">
            <!-- <input type="radio" name="sex" value="男" title="男" checked="">
            <input type="radio" name="sex" value="女" title="女"> -->
            <input style="width: 400px;" type="text" name="applicant" lay-verify="required" lay-reqtext="姓名不能为空" placeholder="请输入申领人姓名" value="" class="layui-input">

        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">申领车间</label>
        <div class="layui-input-block" style="width: 400px;">
            <!-- <input style="width: 400px;" type="text" name="workshopid" lay-verify="required" lay-reqtext="车间不能为空" placeholder="请输入车间" value="" class="layui-input"> -->

            <select id="workshop" name="workshopid" lay-verify="required" lay-reqtext="车间不能为空"  class="layui-input">

            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">申领日期</label>
        <div class="layui-input-block">
            <!-- <input type="datetime" name="applydate" lay-verify="required" lay-reqtext="日期不能为空" placeholder="请输入日期" value="" class="layui-input"> -->
            <input name="applyDate" style="width: 400px;" type="text" lay-verify="required" lay-reqtext="时间不能为空" class="layui-input" id="test1" placeholder="yyyy-MM-dd">
        </div>
    </div>
    <!-- <div class="layui-form-item">
         <label class="layui-form-label">职业</label>
         <div class="layui-input-block">
             <input type="text" name="work" placeholder="请输入职业" value="" class="layui-input">
         </div>
     </div> -->
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">备注信息</label>
        <div class="layui-input-block">
            <textarea style="width: 600px;"  name="remark" class="layui-textarea" placeholder="请输入备注信息"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form','laydate','layer'], function () {
        var laydate = layui.laydate;
        var form = layui.form,
            layer = layui.layer,
            $ = layui.jquery;

        //日期选择
        //常规用法
        laydate.render({
            elem: '#test1'
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            $.ajax({
                url:'/updateapply',
                type:'POST',
                data:data.field,
                dataType:'json',
                success:function(result){
                    var index = layer.alert(result.msg, {
                        title: '最终的提交信息',
                    },function () {
                        // 关闭弹出层
                        layer.close(index);
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);
                        if(result.code==0){
                            window.parent.location.reload();
                        }
                    })
                }
            })

            return false;
        });

        /* 查询所有车间 */
        $(function(){
            var url = location.search;
            var i = url.indexOf("=");
            var id = url.substring(i+1);
            $.ajax({
                url:'/applydataecho',
                type:"GET",
                data:{
                    matId:id
                },
                async:false,
                dataType:"json",
                success:function(data){
                    var workshop = data.workShop;
                    var mr = data.materialRequisition;
                    var content = "";
                    var wsid = mr.workshopid;
                    for(var i = 0;i<workshop.length;i++){
                        var ws = workshop[i];
                        var option ;
                        console.log(ws.wosId +"----"+ wsid);
                        if(ws.wosId == wsid){
                             option = $("<option>").val(ws.wosId).html(ws.wsname).attr('selected','selected');
                        }else{
                            option = $("<option>").val(ws.wosId).html(ws.wsname);
                        }

                        $('#workshop').append(option);
                    }
                    $("#matid").val(mr.matId)
                    $("input[name='planid']").val(mr.planid)
                    $("input[name='applicant']").val(mr.applicant)
                    //$("#workshop").html(content);
                    $("input[name='applyDate']").val(mr.applyDate)
                    $("textarea[name='remark']").val(mr.remark)
                    /*重新渲染页面*/
                    form.render();
                }
            })
        })
    });

</script>
</body>
</html>